package com.five.wisdomClass.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.wisdomClass.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AdminMapper extends BaseMapper<Admin> {

    // 发布公告
    @Insert("INSERT INTO smartcampus.announce(post_time,title,context) VALUES(current_time,#{title},#{context})")
    int postAnnounce(Announce announce);

    // 获取最新时间的一条公告
    @Select("SELECT * FROM smartcampus.announce ORDER BY post_Time DESC LIMIT 1")
    Announce getLatestAnnounce();

    // 查看公告
//    @Select("SELECT * FROM smartcampus.announce")
//    IPage<Announce> showAnnounce(Page<?> page);
    @Select("SELECT * FROM smartcampus.announce ORDER BY post_Time DESC")
    List<Announce> showAnnounce();
    // 查看请假学生
    @Select("SELECT * FROM smartcampus.leave")
    IPage<Leave> getLeaveStudents(Page<?> page);

    /**
     *通过请假申请
     */
    // 通过学生请假申请
    @Update("UPDATE smartcampus.leave SET state = 1,reason = #{reason} WHERE id = #{id}")
    int passStudentLeave(Leave leave);

    // 驳回学生的请假申请
    @Update("UPDATE smartcampus.leave SET state = 2,reason = #{reason} WHERE id = #{id}")
    int refuseStudentLeave(Leave leave);

    // 获取公共课调整申请
    @Select("SELECT * FROM smartcampus.public_course WHERE state in (0,3) ")
    List<Course> getUpdatePublicCourses();

    // 获取选修课调整申请
    @Select("SELECT * FROM smartcampus.take_course WHERE state in (0,3)")
    List<Course> getUpdateTakeCourses();

    // 审核选修课
    @Update("UPDATE smartcampus.take_course SET state = #{state} WHERE id = #{id}")
    int checkTakeCourse(Integer id,Integer state);

    // 审核公共课
    @Update("UPDATE smartcampus.public_course SET state = #{state} WHERE id = #{id}")
    int checkPublicCourse(Integer id,Integer state);

}
